package org.example.IO;

import java.io.*;
import java.util.*;
/**
 * @className: Demo11
 * @author: 芃
 * @description: 从一个文件当中读字节流数据，以字符流的形式写回到另外一个文件当中
 * @date: 2024/5/6 18:34
 */
public class Demo11 {
    public static void main(String[] args) {
        try(InputStream inputStream = new FileInputStream("D:\\My_Code\\Java_Code\\EE_And_System_New\\Test\\src\\main\\java\\org\\example\\IO\\test2.txt")){
            //此时scanner就是从文件读取了！！
            Scanner scanner = new Scanner(inputStream);
            //采用scanner读取文件内容，并将其写入到另一个文件当中
            String str = scanner.nextLine();
            System.out.println(str);
            //将读取到的内容写入到另一个文件当中
/*            try(OutputStream outputStream = new FileOutputStream("D:\\My_Code\\Java_Code\\EE_And_System_New\\Test\\src\\main\\java\\org\\example\\IO\\test.txt")) {
                outputStream.write(str.getBytes());
            } 以字节流的形式写入到文件当中*/
            try(Writer writer = new FileWriter("D:\\My_Code\\Java_Code\\EE_And_System_New\\Test\\src\\main\\java\\org\\example\\IO\\test.txt")){
                writer.write(str);//以字符流的形式写入到文件当中
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
